<html>
<%@ include file="../../common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><fmt:message key="format.message.system" /></title>
</head>

<body>
<script type="text/javascript">
Ext.namespace('azure', 'azure.common');
azure.common.gameDesk = function() {
	var cm_gameDesk;
	var grid_gameDesk, store_gameDesk;
	var mainpanel;
	var toolbar_res;
	var addgameDeskForm,editgameDeskForm;
	var addgameDeskWin,editgameDeskWin;
	var addBettingWin,editBettingWin;
	var grid_Betting,store_Betting,cm_Betting;
	var addBettingForm,editBettingForm;
	// 創建ColumnModel
	function createCM() {
		cm_gameDesk = new Ext.grid.ColumnModel([
		{header : '<fmt:message key="format.content.GameDesk" />',dataIndex : 'deskName'},
		{header : '<fmt:message key="format.content.WEBSITE" />',dataIndex : 'website'},
		{header : '<fmt:message key="format.content.Status" />',dataIndex : 'status'},
		{header : '<fmt:message key="format.content.Operation" />',dataIndex : 'status',renderer : function(val, p, record) {
			var str;
			if(val == 'closed'){
				str = '<a href="#" onclick="javascript:statusUpdate(\'running\');"}><fmt:message key="format.content.open" /></a>'
			}else{
				str = '<a href="#"} onclick="javascript:statusUpdate(\'closed\');"><fmt:message key="format.content.close" /></a>'
			}
			return '<b><a href="#" onclick="javascript:editgameDesk();"}><fmt:message key="format.content.update" /></a>&nbsp; '+
			'<a href="#" onclick="javascript:delgameDesk();"}><fmt:message key="format.content.delete" /></a>&nbsp; '+str+'</b>';
		}}
		]);
	}

	function createStore() {
		store_gameDesk = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : 'GameTable_findByPage.action'
			}),
			reader : new Ext.data.JsonReader({
				root : 'pager.data',
				totalProperty : 'pager.totalSize'
			}, [{
				name : 'gtno',
				mapping : 'gtno'
			}, {
			name : 'deskName',
			mapping : 'deskName'
		}, {
			name : 'website',
			mapping : 'website'
		}, {
			name : 'status',
			mapping : 'status'
		}
		, {
			name : 'openTime',
			mapping : 'openTime'
		}, {
			name : 'closeTime',
			mapping : 'closeTime'
		}, {
			name : 'endBettingTimeout',
			mapping : 'endBettingTimeout'
		}, {
			name : 'drawLotteryInterval',
			mapping : 'drawLotteryInterval'
		}
		
		])
		});
		store_gameDesk.load({params:{start:0,limit:15,'game.gameno':Ext.getCmp('gamedesk').idvalue}});

	}

	function createGrid() {
		createCM();
		createStore();

		grid_gameDesk = new Ext.grid.GridPanel({
			cm : cm_gameDesk,
			store : store_gameDesk,
			height : 450,
			tbar:[{text:'<fmt:message key="format.content.add" />',handler:addgameDesk},{text:'<fmt:message key="format.content.update" />',handler:editgameDesk},
				{text:'<fmt:message key="format.content.delete" />',handler:function() {
							var dict = grid_gameDesk.getSelections()[0];
							if (dict != null) {
								Ext.MessageBox.confirm('<fmt:message key="format.content.delete" />', '<fmt:message key="format.content.isdelete" />', doDel)
							} else {
								Ext.MessageBox.alert('<fmt:message key="format.content.Tips" />', '<fmt:message key="format.content.aterror" />');
							}
						}
			}],
			bbar : new Ext.PagingToolbar({
				store : store_gameDesk,
				pageSize : 15,
				displayInfo : true,
				displayMsg : '<fmt:message key="format.content.pager" />',
				emptyMsg : '<fmt:message key="format.content.emptyMsg" />'
			})
		});
	}

	function createUI() {
		createGrid();
		createForm();

		mainpanel = new Ext.Panel({
			frame : false,
			id:'playPanel',
			renderTo :'gameDeskDiv',
			layout:'fit',
			items : [grid_gameDesk]
		});
	}

	function createForm() {

		addgameDeskForm = new Ext.form.FormPanel({
			labelWidth : 65,
			frame : true,
			url:'GameTable_create.action',
			labelSeparator : ':',
			labelAlign : 'left',
			defaultType : 'textfield',
			items : [
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.deskName" />',
				width : 220,
				name : 'gameTable.name'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.WEBSITE" />',
				name : 'gameTable.website',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.openTime" />',
				name : 'gameTable.operationTime.openTime',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.closeTime" />',
				name : 'gameTable.operationTime.closeTime',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.drawLotteryInterval" />',
				name : 'gameTable.operationTime.drawLotteryInterval',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.endBettingTimeout" />',
				name : 'gameTable.operationTime.endBettingTimeout',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			})]
		});

		editgameDeskForm = new Ext.form.FormPanel({
			labelWidth : 65,
			frame : true,
			url:'GameTable_merge.action',
			labelSeparator : ':',
			labelAlign : 'left',
			defaultType : 'textfield',
			items : [
			new Ext.form.Hidden({
				id:'gtno',
				name : 'gameTable.gtno'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.deskName" />',
				width : 220,
				id:'name',
				name : 'gameTable.name'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.WEBSITE" />',
				id:'website',
				name : 'gameTable.website',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.openTime" />',
				id:'openTime',
				name : 'gameTable.operationTime.openTime',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.closeTime" />',
				id:'closeTime',
				name : 'gameTable.operationTime.closeTime',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.drawLotteryInterval" />',
				id:'drawLotteryInterval',
				name : 'gameTable.operationTime.drawLotteryInterval',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.content.endBettingTimeout" />',
				id:'endBettingTimeout',
				name : 'gameTable.operationTime.endBettingTimeout',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			})]
		});
	}
	


	function addgameDesk() {
		addgameDeskWin = new Ext.Window({
			width : 420,
			height : 300,
			closable : false,
			layout : 'fit',
			items : addgameDeskForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.content.Determine" />',
				handler : create,
				formBind : true
			}, {
				text : '<fmt:message key="format.content.Cancel" />',
				handler : function(){
					addgameDeskWin.hide();
				}
			}]
		});
		addgameDeskWin.title = '<fmt:message key="format.content.gameDeskAdd" />';
		addgameDeskWin.show(Ext.getBody());
	}

	editgameDesk =function () {
		editgameDeskWin = new Ext.Window({
			width : 800,
			height : 520,
			closable : false,
			layout : 'fit',
			items : editgameDeskForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.content.Determine" />',
				handler:update,
				formBind:true
			}, {
				text : '<fmt:message key="format.content.Cancel" />',
				handler : function() {
					editgameDeskWin.hide();
				}
			}]
		});
		var rec = grid_gameDesk.getSelections()[0];
		if (rec != null) {
			editgameDeskWin.title = '<fmt:message key="format.content.gameDeskEdit" />';
			editgameDeskWin.show(Ext.getBody());
			editgameDeskForm.getForm().loadRecord(rec);
		} else {
			Ext.MessageBox.alert('<fmt:message key="format.content.Warning" />', '<fmt:message key="format.content.aterror" />');
		}

	}

	function update(btn) {
		if(editgameDeskForm.getForm().isValid()){
			btn.disable();
			editgameDeskForm.getForm().submit({
				method : 'POST',
				waitMsg : '<fmt:message key="format.content.updating" />',
				successProperty : false,
				params:{'gameTable.game.gameno':Ext.getCmp('gamedesk').idvalue},
				success : function() {
					Ext.Msg.alert('<fmt:message key="format.content.Success" />', '<fmt:message key="format.content.updateSuccess" />',function() {
						btn.enable();
						store_gameDesk.reload();
					});
				},
				failure : function() {
					Ext.Msg.alert('<fmt:message key="format.content.Failure" />', '<fmt:message key="format.content.updateFailure" />');
					btn.enable();
				}
			});
			}
	}
	
	function create(btn) {
		if(addgameDeskForm.getForm().isValid()){
			btn.disable();
			addgameDeskForm.getForm().submit({
				method : 'POST',
				waitMsg : '<fmt:message key="format.content.saving" />',
				successProperty : false,
				params:{'gameTable.game.gameno':Ext.getCmp('gamedesk').idvalue},
				success : function() {
					Ext.Msg.alert('<fmt:message key="format.content.Success" />', '<fmt:message key="format.content.saveSuccess" />',function() {
						btn.enable();
						store_gameDesk.reload();
					});
				},
				failure : function() {
					Ext.Msg.alert('<fmt:message key="format.content.Failure" />', '<fmt:message key="format.content.saveFailure" />');
					btn.enable();
				}
			});
			}
	}

	statusUpdate = function (status){
		var rec = grid_gameDesk.getSelections()[0];
		Ext.MessageBox.wait('等待...');
		Ext.Ajax.request( {
			url : 'GameTable_updateStatus.action',
			method : 'GET',
			params : {
				'gameTable.gtno' : rec.data.gtno,
				'gameTable.status':status
			},
			success : function(response) {
				grid_gameDesk.getStore().reload();
				Ext.MessageBox.hide();
			},
			failure : function() {
				Ext.Msg.show( {
					title : '错误提示',
					msg : '发生错误!',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR
				});
			}
		});
		
	}
	
	delgameDesk=function (){
		var dict = grid_gameDesk.getSelections()[0];
		if (dict != null) {
			Ext.MessageBox.confirm('<fmt:message key="format.content.delete" />', '<fmt:message key="format.content.isdelete" />', doDel)
		} else {
			Ext.MessageBox.alert('<fmt:message key="format.content.Tips" />', '<fmt:message key="format.content.aterror" />');
		}
	}
	function doDel(d){
		if (d == 'yes') {
			var r = grid_gameDesk.getSelectionModel().getSelected();
			var rec = grid_gameDesk.getSelections()[0];
			Ext.MessageBox.wait('<fmt:message key="format.content.wait" />');
			Ext.Ajax.request( {
				url : 'GameTable_delete.action',
				params : {
					'gameTable.gtno' : rec.data.gtno
				},
				success : function(response) {
					grid_gameDesk.getStore().remove(rec);
					Ext.MessageBox.hide();
				},
				failure : function() {
					Ext.Msg.show( {
						title : '<fmt:message key="format.content.errortitle" />',
						msg : '<fmt:message key="format.content.errormsg" />',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR
					});
				}
			});
			
		}
	}
	
	return {
		init : function() {
			createUI();
		}
	};

}();
Ext.onReady(azure.common.gameDesk.init, azure.common.gameDesk, true);
</script>

<div id="gameDeskDiv"></div>
</body>
</html>
